from flask import Flask
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from geoalchemy2 import Geometry
from sqlalchemy import Column, Integer, TIMESTAMP
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = "postgresql://postgres:postgresql@localhost:5432/crowdsourcingDB"
db = SQLAlchemy(app)
migrate = Migrate(app, db)
engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])


class TaskModel(db.Model):
    __tablename__ = 'task'
    id = Column(Integer, primary_key=True)
    the_geom = Column(Geometry(geometry_type='POINT', management=True))
    type = Column(Integer)
    time = Column(TIMESTAMP)


Session = sessionmaker(bind=engine)
session = Session()

query = session.query(TaskModel).order_by(TaskModel.id)
for atask in query:
    print(atask.id)
    print(atask.type)
    print(atask.the_geom)
    print(atask.time)
    break
